/**
 * 撲克事件接收類，用於調用
 */
function pokerAc() {		
	/**
	 * 擴展功能，注意通用參數
	 */
	if ( pokerAc.prototype.handleFun == undefined ) {
		pokerAc.prototype.handleFun = function(r_room, r_user, r_params) {
			if (r_user == null) {
				__log.show(r_params);	//一般來說怎麼會出現用戶丟失呢
			}else {
				if (r_room == null || r_room == undefined || r_room == -1) {
					var _ac = r_params.ac;
					if (_ac != 'getRoomList' && _ac != 'joinRoom' ) {
						r_room = _zone.getRoom((r_user.getRoomsConnected())[0]);
					}
				}
			}
			return this[r_params.ac](r_room,r_user,r_params);
		}		
	}	
}
/**
 * 會員叫牌事件
 * 條件：是否輪到該用戶，用戶是否allin過，用戶是否棄牌過，用戶是否
 */
pokerAc.prototype.bet = function(r_room, r_user, r_params) {
	var _action = ['call', 'raise', 'fold', 'allIn', 'check', 'bet'];//0,1,2,3,4,5
	var _type = { call:0, raise:1, fold:2, allIn:3, check:4, bet:5 };
	var _params = { };	
	_params._cmd = "bet";
	var _data = { };
	if (r_user.isSpectator() && r_user.getVariable("state") != 1) {
		return;
	}
	if (parseInt(r_room.getVariable("state").value) == 2) {
		var _index = parseInt(r_room.getVariable("index").value);
		var _index_arr = r_room.properties.get("indexArr");
		var _allIn = r_room.properties.get("allIn");
		var _fold = r_room.properties.get("fold");
		var _sit = r_user.getPlayerIndex();
		var _next = false;		
		var _way = _action[r_params['way']];
		__log.show(_allIn);
		if ( in_array(r_user.getPlayerIndex(), _allIn)) {//用户已经allin
			_data['way'] = 3;
		}else if ( in_array(r_user.getPlayerIndex(), _fold)) {//用户已经弃牌
			_data['way'] = 2;
		}else if ( _index_arr[_index] == r_user.getPlayerIndex() || _way == 'bet') {
			var _result = __betEvent.handleFun(r_room, r_user, _action[r_params['way']], parseInt(r_params['chip']));
			__log.show(_result);
			if (_result == false) {
				_data = { err:7010 };//下注金额与下载方式不符
			}else{
				_data['way'] = _type[_result['type']];
				_data['chip'] = (_result['chip'] == undefined ) ? 0 : _result['chip'];
				_data['uid'] = parseInt(r_user.getName());
				_data['bank'] = (_result['bank'] == undefined ) ? parseInt(r_user.getVariable("bank").value) : _result['bank'];
				_next = (_result['next'] == undefined) ? true : _result['next'];
			}			
		}else {
			_data = { err: 7009};//不是當前用戶叫牌
		}
		_params.dataObj = _data;
	}else {
		_params.dataObj = { err: 7009};//不是當前用戶叫牌
	}	
	_server.sendResponse(_params, -1, null, r_room.getAllUsers(), 'json');	
	if (_next) {
		__userEvent.nextUserAction(r_room, r_user);
	}
}